//
// Created by v on 2025/11/18.
//

#include "CMStorageManager.h"
#include "utils/rt_print.h"

CMStorageManager::CMStorageManager(std::string &dev_path)
{
    device_name = dev_path;
    storage_init();
}
CMStorageManager::~CMStorageManager() {}
size_t CMStorageManager::all_size()
{
    return pri_vfs.f_blocks * pri_vfs.f_frsize;
}
size_t CMStorageManager::free_size()
{
    return pri_vfs.f_bfree * pri_vfs.f_frsize;
}
size_t CMStorageManager::available_size()
{
    return pri_vfs.f_bavail * pri_vfs.f_frsize;
}
int    CMStorageManager::storage_init()
{
    int ret = statvfs(device_name.c_str(), &pri_vfs);
    if (ret != 0)
    {
        rterror("stat failed ret = [%d]\n", ret);
        return ret;
    }
    return 0;
}

